<template>
	<view style="height:100%; width: 100%; background-color:aliceblue;">
		<view class="content" style="align-items: center;">
			<view class="uni-flex uni-row" style="padding-left: 38%;">
				<view class="uni-center text" :class="approvaltype == '0' ? 'active' : 'unactive'" id="0" @click="changeuser">未审批</view>
				<view class="uni-center text" :class="approvaltype == '1' ? 'active' : 'unactive'" id="1" @click="changeuser">已审批</view>
			</view>
			<view class="uni-column" style="margin: 5%;">
				<view  class="uni-row" style="height: 5%;width: 100%;margin-top: 2%;">
					<text style="width: 30%;margin-left: 12%; font-weight: 700;">时间</text>
					<text style="width: 30%;margin-left: 25%;font-weight: 700;">用户</text>
					<text style="width: 30%;margin-left: 20%;font-weight: 700;">导师类型</text>
				</view>
			</view>
			<view style="padding-left: 5%;"/>
			<view  v-for="apply in datalist">
				<view style="margin-top: 3%;" @click="godetail(apply.apply_id)">
					<view class="bottom-line" style="height: 5%;width: 100%;">
						<text style="width: 20%;">{{gettime(apply.apply_time)}}</text>
						<text style="margin-left: 13%;width: 20%;">{{apply.s_name}}</text>
						<text style="margin-left: 20%;width: 20%;">{{apply.type_name}}导师</text>
					</view>
				</view>		
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 申请列表
				applylist:[],
				//已审批的申请列表
				donelist:[],
				httpurl: getApp().globalData.weburl,
				//渲染数据源
				datalist:[],
				approvaltype:'0',
			}
		},
		computed:{
			gettime() {
			    return (time) => {
					var l=time.split('-');
					var m=l[2].split(' ');
					var t=m[1].split('+');
					l[1]=l[1][0]=='0'? ' '+l[1][1]:l[1];
					console.log(l[0]+'年'+l[1]+'月'+m[0]+'日 '+ m[1]);
				    return l[0]+'年'+l[1]+'月'+m[0]+'日 ';
			    }
			},
			getyear() {
			    return (time) => {
					var l=time.split('-');
				    return 'year'+l[0]
			    }
			}
		},
		methods: {
			godetail(apply_id){
				console.log(apply_id);
				uni.navigateTo({
					url:"./teacherdetail/teacherdetail?apply_id="+apply_id
				})
			},
			changeuser(e){
				console.log("切换选择内容为："+e.currentTarget.id);
				var that = this;
				this.approvaltype=e.currentTarget.id;
				console.log(this.approvaltype);
				if(this.approvaltype == '0'){
					this.datalist = this.applylist;
					console.log(this.applylist);
					console.log(this.datalist);
				}
				if(this.approvaltype == '1'){
					this.datalist = this.donelist;
				}
			},
			getTeacher(){
				var that = this;
				uni.request({
				    url: that.httpurl+'getTeacherApply', //服务器地址+接口名
				    data: {
					 M_id:getApp().globalData.userid,
				    },
					method: 'POST',
				    header: {
					  'X-Requested-With': 'XMLHttpRequest',
					  "Accept": "application/json",
					  "Content-Type": "application/json; charset=UTF-8"
					 },
					dataType: 'json',
				 success: (res) => {
					 that.applylist = res.data.applylist;
					 that.datalist = that.applylist;
				 },
				 fail:(res) =>{
					 console.log("获取导师申请列表失败");
					 }
				 });
				 uni.request({
				     url: that.httpurl+'getManagerApproval', //服务器地址+接口名
				     data: {
				 	 M_id:getApp().globalData.userid,
				     },
				 	method: 'POST',
				     header: {
				 	  'X-Requested-With': 'XMLHttpRequest',
				 	  "Accept": "application/json",
				 	  "Content-Type": "application/json; charset=UTF-8"
				 	 },
				 	dataType: 'json',
				  success: (res) => {
				 	 that.donelist = res.data.donelist;
		
				  },
				  fail:(res) =>{
				 	 console.log("获取完成的导师申请列表失败");
				 	 }
				  })
			}
		},
		onLoad() {
			uni.setNavigationBarTitle({
				title:'导师审批'
			})
			this.getTeacher();
		},
	}
</script>

<style>
page {
  height: 100%;
}
.card{
	position: absolute; 
	width:100%;
	height:auto; 
	top:15%;
	display: flex; 
	flex-direction: row; 
	/*align-items: center;  //垂直居中*/
	justify-content: center; //水平居中
}
.login_form{
	width:85%;
	height: auto;
	background-color:white;
	border-radius: 10px;
	display: flex;
	flex-direction: row; 
	/*align-items: center;  //垂直居中*/
	justify-content: center; //水平居中
}
.content{
	width:90%;
	height: auto;
}

.shadow{
	box-shadow: 0 2rpx 4rpx rgba(0, 0, 0, .3);
}
.active{
	border-bottom:2px solid #528FFF;
	color:#528FFF;
	font-weight: 450;
}

.text {
	margin: 15rpx 15rpx;
	padding: 0 5rpx;
	height: 70rpx;
	line-height: 70rpx;
	text-align: center;
	font-size: 30rpx;
}
.input{
	margin-top: 10px;
	border-radius: 10px;
	background-color: #eaeeee;
}


.user-insert-line::before {
    position: absolute;
    right: 25px;
    bottom: 0;
    top: 6rem;
    left: 32px;
    height: 1px;
    content: '';
    -webkit-transform: scaleY(.5);
    transform: scaleY(.5);
    background-color: #a3a2a6;
}
.bottom-line{
	border-top:1px solid #bfbec2;
	padding: 3%;

}
</style>
